package com.woniuxy.his.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.his.controller.form.AddArrangeForm;
import com.woniuxy.his.entity.Arrange;
import com.woniuxy.his.mapper.ArrangeMapper;
import com.woniuxy.his.service.IArrangeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.his.vo.ArrangeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 排班表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-24
 */
@Service
@Slf4j
public class ArrangeServiceImpl extends ServiceImpl<ArrangeMapper, Arrange> implements IArrangeService {

    @Resource
    private ArrangeMapper arrangeMapper;

    //删除arrangId的这条数据
    @Override
    public Integer delArrange(Integer arrangeId) {
        Integer integer = arrangeMapper.delArrange(arrangeId);
        return integer;
    }

    @Override
    public IPage<ArrangeVo> findArrangeByPage(String arrangeTime,Integer current,Integer size) {
        log.info("安排时间为{}",arrangeTime);
        IPage page=new Page(current,size);
        IPage pageResult = arrangeMapper.findArrangeByTime(page,arrangeTime);

        if(null!=pageResult){
            return pageResult;
        }
        return null;
    }

    @Override
    public Integer addArrange(AddArrangeForm addArrangeForm) throws ParseException {
        Arrange arrange = new Arrange();
        arrange.setArrangeNum(15);
        arrange.setDoctorId(addArrangeForm.getDoctorId());
        String arrangeTime = addArrangeForm.getArrangeTime();
        arrange.setArrangeTime(arrangeTime);
//        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//        Date parse = sdf.parse(arrangeTime);
//
//        arrange.setArrangeTime(parse);

        int insert = arrangeMapper.insert(arrange);

        return insert;
    }

    @Override
    public IPage<ArrangeVo> findArrangeByPage2(Integer current, Integer size) {
        log.info("一进来展示全部排版信息");
        IPage page=new Page(current,size);
        IPage pageResult = arrangeMapper.findArrangeByTime2(page);
        if(null!=pageResult){
            return pageResult;
        }
        return null;
    }

    @Override
    public Integer updateArrange(AddArrangeForm addArrangeForm) {
        log.info("业务层修改排班信息");
        Integer integer = arrangeMapper.updateArrange(addArrangeForm);
        return integer;

    }
}
